﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace InChatter.Client.WPFClient.Utility
{
    public class DelegateCommand<T>:ICommand
    {
        private Action<T> action;
        private Func<bool> canFunc;
        public DelegateCommand(Action<T> action, Func< bool> canFunc)
        {
            this.action = action;
            this.canFunc = canFunc;
        }
        public DelegateCommand(Action<T> action)
        {
            this.action = action;
        }
        public bool CanExecute(object parameter)
        {
            if (canFunc != null)
            {
                return canFunc();
            }
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            if (action != null)
            {
                action((T)parameter);
            }
        }

    }

    public class DelegateCommand : ICommand
    {
        private Action action;
        private Func<bool> canFunc;
        public DelegateCommand(Action action, Func<bool> canFunc)
        {
            this.action = action;
            this.canFunc = canFunc;
        }
        public DelegateCommand(Action action)
        {
            this.action = action;
        }
        public bool CanExecute(object parameter)
        {
            if (canFunc != null)
            {
                return canFunc();
            }
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            if (action != null)
            {
                action();
            }
        }

    }
}
